package me.stephenj.contactsweb.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

@Component
public interface LoginMapper {
    @Select("SELECT `password` FROM users WHERE `username`=#{username}")
    String getPassword(String username);

    @Select("SELECT `sessionId` FROM users WHERE `username`=#{username}")
    String getSessionId(String username);

    @Select("SELECT `username` FROM users WHERE `sessionId`=#{sessionId}")
    String getUsername(String sessionId);

    @Update("UPDATE `users` SET `sessionId`=#{sessionId} WHERE `username`=#{username}")
    int updateSessionId(String username, String sessionId);

    @Update("UPDATE `users` SET sessionId=null WHERE sessionId=#{sessionId}")
    int deleteSessionId(String sessionId);
}
